package address.controller;

import common.model.user.Address;
import common.model.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import address.service.IAddressService;

import java.util.List;

@RestController
@RequestMapping("/address")
public class AddressController {
    @Autowired
    private IAddressService addressService;
    //获取地址列表
    @RequestMapping("/list")
    public Result list(@RequestHeader Long uid) {
        //根据uid获取地址列表
        List<Address> addresses = addressService.list(uid);
        return Result.success(addresses);
    }
    //获取默认地址
    @RequestMapping("/default")
    public Result getDefault(@RequestHeader Long uid) {
        //根据uid获取默认地址
        Address address = addressService.getDefault(uid);
        return Result.success(address);
    }
    //创建地址
    @RequestMapping("/create")
    public Result create(@RequestBody Address address) {
        //创建地址
        addressService.create(address);
        return Result.success();
    }
    //修改地址
    @RequestMapping("/update")
    public Result update(@RequestBody Address address) {
        //修改地址
        addressService.update(address);
        return Result.success();
    }
    //删除地址
    @RequestMapping("/delete")
    public Result delete(@RequestParam Long id) {
        //删除地址
        addressService.delete(id);
        return Result.success();
    }
}
